import java.io.*;
import java.util.Scanner;

/**
 * @author LinLe
 * @create 2020-12-21 16:36
 */
public class DeleteRunnable implements Runnable {
    private  Scanner sn = new Scanner(System.in);
    private boolean flag = false;
    void deleteFile(File file) {
        if(file == null || !file.exists()){
            System.out.println("目录或文件不存在");
            return;
        }
        File[] files = file.listFiles();
        for (File file1 : files
             ) {
            System.out.println(file1.getName());
            //是目录就进行递归
            if (file1.isDirectory()) {
                deleteFile(file1);
            } else {
                //是文件就进行删除
                file1.delete();
            }
        }
        //最后删除所有空目录
        file.delete();
        flag = true;
    }
    
    
    
    @Override
    public void run() {
        System.out.print("请输入你要删除的目录：");
        String nameFile = sn.next() ;
        File file = new File(nameFile);
        deleteFile(file);
        if(flag){
            System.out.println("删除成功");
        }
    }
}
